$(function(){
	
	var total = 0;
			
	$("span[id^='count']").each(function(index){
		total+= parseFloat($(this).html());
	});
	
	$("#total").html(total);
	$("#total1").val(total);
	
	$("select[name='days']").change(function(){
		
		var id = $(this).attr("id").substring(4,$(this).attr("id").length);
		
		$.post("getDiscount!getDiscount.do",{days:$(this).val()},function(obj){
			//折扣率
			var percent = parseFloat(obj.discountPrice);
			//购买天数
			var days = obj.days;
			//单价
			var price = parseFloat($("#price"+id).text());
			//总价
			var count = Math.round(price*days*percent)/100;
			
			$("#discount"+id).text(percent+"%");
			$("#count"+id).text(count);
			//总共价格
			var total = 0;
			
			$("span[id^='count']").each(function(index){
				total+= parseFloat($(this).html());
			});
			
			$("#total").html(total);
			$("#total1").val(total);
		});
		
		
		
	});	
	
	
	var submit = function(){
		
		var ipid,days;
		
		
		
	};
	
});